<?php

namespace App\Console\Commands;

use App\Model\Order;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;

class StoreNiceForOrder extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'store_nice_order';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '同步点赞数到订单表';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $orders = Order::where(['order_status'=>1, 'pay_status'=>1])->get();
        if($orders->isNotEmpty()){
            foreach ($orders as $order){
                $niceCount = Redis::scard('order:'.$order->id);
                $order->nice = $niceCount;
                $order->save();
            }
            Log::info('redis order nice sync mysql success');
            $this->info('redis order nice sync mysql success');
        }else{
            Log::info('not find order');
            $this->error('not find order');
        }
    }
}
